package com.company.emallbackend.common;

import com.company.emallbackend.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author hanlijian
 * @create 2023-01-13-10:46
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private JwtInterceptor jwtInterceptor;

    /**
     * 加自定义拦截器JwtInterceptor，设置拦截规则
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/register","/user/email","/product/page","/product/findAll","/product/getById/**","/order/notify","/order/ok")
                .excludePathPatterns("/swagger**/**", "/webjars/**", "/v3/**", "/doc.html", "","/favicon.ico");  // 排除 swagger拦截
    }
}